package cn.iocoder.yudao.module.biz.controller.admin.emergencyReservePlainDrill;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.biz.controller.admin.emergencyReservePlainDrill.vo.*;
import cn.iocoder.yudao.module.biz.dal.dataobject.emergencyReservePlainDrill.BizEmergencyReservePlainDrillDO;
import cn.iocoder.yudao.module.biz.convert.emergencyReservePlainDrill.BizEmergencyReservePlainDrillConvert;
import cn.iocoder.yudao.module.biz.service.emergencyReservePlainDrill.BizEmergencyReservePlainDrillService;

@Api(tags = "管理后台 - 演练计划")
@RestController
@RequestMapping("/biz/emergency-reserve-plain-drill")
@Validated
public class BizEmergencyReservePlainDrillController {

    @Resource
    private BizEmergencyReservePlainDrillService emergencyReservePlainDrillService;

    @PostMapping("/create")
    @ApiOperation("创建演练计划")
    @PreAuthorize("@ss.hasPermission('biz:emergency-reserve-plain-drill:create')")
    public CommonResult<String> createEmergencyReservePlainDrill(@Valid @RequestBody BizEmergencyReservePlainDrillCreateReqVO createReqVO) {
        return success(emergencyReservePlainDrillService.createEmergencyReservePlainDrill(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新演练计划")
    @PreAuthorize("@ss.hasPermission('biz:emergency-reserve-plain-drill:update')")
    public CommonResult<Boolean> updateEmergencyReservePlainDrill(@Valid @RequestBody BizEmergencyReservePlainDrillUpdateReqVO updateReqVO) {
        emergencyReservePlainDrillService.updateEmergencyReservePlainDrill(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除演练计划")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermission('biz:emergency-reserve-plain-drill:delete')")
    public CommonResult<Boolean> deleteEmergencyReservePlainDrill(@RequestParam("id") String id) {
        emergencyReservePlainDrillService.deleteEmergencyReservePlainDrill(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得演练计划")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = String.class)
    @PreAuthorize("@ss.hasPermission('biz:emergency-reserve-plain-drill:query')")
    public CommonResult<BizEmergencyReservePlainDrillRespVO> getEmergencyReservePlainDrill(@RequestParam("id") String id) {
        BizEmergencyReservePlainDrillDO emergencyReservePlainDrill = emergencyReservePlainDrillService.getEmergencyReservePlainDrill(id);
        return success(BizEmergencyReservePlainDrillConvert.INSTANCE.convert(emergencyReservePlainDrill));
    }

    @GetMapping("/list")
    @ApiOperation("获得演练计划列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('biz:emergency-reserve-plain-drill:query')")
    public CommonResult<List<BizEmergencyReservePlainDrillRespVO>> getEmergencyReservePlainDrillList(@RequestParam("ids") Collection<String> ids) {
        List<BizEmergencyReservePlainDrillDO> list = emergencyReservePlainDrillService.getEmergencyReservePlainDrillList(ids);
        return success(BizEmergencyReservePlainDrillConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得演练计划分页")
    @PreAuthorize("@ss.hasPermission('biz:emergency-reserve-plain-drill:query')")
    public CommonResult<PageResult<BizEmergencyReservePlainDrillRespVO>> getEmergencyReservePlainDrillPage(@Valid BizEmergencyReservePlainDrillPageReqVO pageVO) {
        PageResult<BizEmergencyReservePlainDrillDO> pageResult = emergencyReservePlainDrillService.getEmergencyReservePlainDrillPage(pageVO);
        return success(BizEmergencyReservePlainDrillConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出演练计划 Excel")
    @PreAuthorize("@ss.hasPermission('biz:emergency-reserve-plain-drill:export')")
    @OperateLog(type = EXPORT)
    public void exportEmergencyReservePlainDrillExcel(@Valid BizEmergencyReservePlainDrillExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<BizEmergencyReservePlainDrillDO> list = emergencyReservePlainDrillService.getEmergencyReservePlainDrillList(exportReqVO);
        // 导出 Excel
        List<BizEmergencyReservePlainDrillExcelVO> datas = BizEmergencyReservePlainDrillConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "演练计划.xls", "数据", BizEmergencyReservePlainDrillExcelVO.class, datas);
    }

}
